package chapone

import (
	"flag"
	"fmt"
	"log"
)

// 子命令的使用
var name string

// go run main.go go -name=hello go run main.go php -n=world
func FlagDemo02() {
	flag.Parse()

	goCmd := flag.NewFlagSet("go", flag.ExitOnError)
	goCmd.StringVar(&name, "name", "GO语言", "帮助信息")
	phpCmd := flag.NewFlagSet("php", flag.ExitOnError)
	phpCmd.StringVar(&name, "n", "php语言", "帮助信息")

	args := flag.Args()
	fmt.Println(args, len(args))
	switch args[0] {
	case "go":
		_ = goCmd.Parse(args[1:])
	case "php":
		_ = phpCmd.Parse(args[1:])

	}

	log.Printf("name:%s", name)
}
